package com.gxa.hystrix.service;

import com.gxa.hystrix.interfaces.ServiceFeignByChuFangMoBan;

import com.gxa.hystrix.pojo.ChuFangMoBan;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author thinknovo
 * @version 1.0
 * @description CheckService.java
 * @date 2021/3/11 9:25
 */
@Service
public class ChuFangMoBanService {
    @Resource
    private ServiceFeignByChuFangMoBan serviceFeignByChuFangMoBan;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解checkError定义的方法
    // 熔断器会检查所有的client是否存在，如果都不存在，则会触发HystrixCommand
    @HystrixCommand(fallbackMethod = "chaXunChuFangMoBanError")
    public Map chaXunChuFangMoBan(String chuFangLeiXing,String moBanBianHao,String moBanMingCheng,String moBanQuanXian) {
        return serviceFeignByChuFangMoBan.chaXunChuFangMoBan(chuFangLeiXing, moBanBianHao,moBanMingCheng,moBanQuanXian);
    }
    public Map chaXunChuFangMoBanError(String chuFangLeiXing,String moBanBianHao,String moBanMingCheng,String moBanQuanXian) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }
    @HystrixCommand(fallbackMethod = "xinZengChuFangMoBanError")
    public Map xinZengChuFangMoBan(ChuFangMoBan chuFangMoBan) {
        return serviceFeignByChuFangMoBan.xinZengChuFangMoBan(chuFangMoBan);
    }
    public Map xinZengChuFangMoBanError(ChuFangMoBan chuFangMoBan) {
        Map map = new HashMap();
        map.put("code", 500);
        map.put("msg","服务异常，请稍后重试！");
        return map;
    }

}
